<template>
  <el-select
    clearable
    filterable
    placeholder="-请选择年级-"
    class="ele-block"
    :value="value"
    @change="changeGradeId">
    <el-option v-for="item in option" :key="item.id" :label="item.name" :value="item.id"/>
  </el-select>
</template>

<script>
export default {
  props: {
    value: {
      type: Number,
      default:7
    },
  },
  model: {
    prop: 'value',
    event: 'change',
  },
  data: function () {
    return {
      option: [],
      loading: false,
    };
  },
  mounted() {
    this.loading = true
    this.$http.get('/grade/getGradeList').then(res => {
      if (res.data.code === 0) {
        this.option = res.data.data;
        this.$emit('changeGrade',this.option && this.option.length > 0 ? this.option[0].id : '');
      } else {
        this.$message.error(res.data.msg);
      }
      this.loading = false
    }).catch(e => {
      this.loading = false
      this.$message.error(e.message);
    });
  },
  methods: {
    changeGradeId(val) {
      this.$emit('changeGradeId', val);
    }
  },
};
</script>
